import type { ResponseOption } from "../../res/ResponseOption.js";
import { fields, ResOp } from "./utils.js";

// 0x00 05 状态寄存器发生变化
export const statusRegisterChange: ResponseOption = {
    name: "0x00 05 状态寄存器发生变化",
    description: "状态寄存器发生变化",
    fields: [
        fields.op(ResOp.StatusRegisterChange),
        fields.crc,
        fields.length,
        {
            name: "状态寄存器",
            kind: "custom",
            desc: "循环：每个状态寄存器由 ID(u8)、值(u16)组成",
            matcher(data) {
                let str = "";
                while (data.length > 0) {
                    const id = data.u8();
                    data.consume(1);
                    const value = data.u16le();
                    data.consume(2);
                    if (str !== "") {
                        str += ", ";
                    }
                    str += `id: ${id}, value: ${value}`;
                }
                return str;
            },
        },
    ],
};
